package org.csource.quickstart.processor.group;

import org.csource.quickstart.FResult;
import org.csource.quickstart.processor.ProcessorChannel;
import org.csource.quickstart.processor.ProcessorOrder;
import org.csource.quickstart.request.UploadRequest;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.FutureCallback;

@Service
@ProcessorOrder(order=10)
@ProcessorChannel(channel="group1")
public class Group1Processor1 extends AbstractChannelProcessor {

  private final String name = "group1_p1";
  
  @Override
  protected FResult<JSONObject> doProcess(UploadRequest request, FutureCallback<Object> response) {
    try {
      System.out.println(name);
      if (response!=null) {
        response.onSuccess(name+"response ok");
      }
      JSONObject o = new JSONObject();
      o.put("name", name);
      return FResult.newSuccess(o);
    } catch (Exception e) {
      return FResult.newFailure(1, e.getMessage());
    }
  }

  @Override
  protected FutureCallback<Object> getFutureCallback() {
    return new FutureCallback<Object>() {
      @Override
      public void onSuccess(Object result) {
        System.out.println("rec:"+result);
      }

      @Override
      public void onFailure(Throwable t) {
        
      }
    };
  }
  
}